﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;

public partial class FlowSet : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session["UserName"] == null || Session["roleID"] == null)
        {
            Response.Redirect("login.aspx");
            Response.End();
        }
        if (Session["roleID"].ToString() != "1")
        {
            Response.Redirect("FLOWModelList.aspx");
        }
        if (!Page.IsPostBack)
        {
            BindToDdlFlowMType();            
            lblUserName.Text =BasicClass.GetTrueNameByUserName(Session["UserName"].ToString());
        }

    }
    private void BindToDdlFlowMType()
    {
        string sqlString = "select * from FLOWTYPE order by FLOWTYPEID ASC";
        DBOperation DBO = new DBOperation();
        SqlDataReader sdr = DBO.GetDataReader(sqlString);
        ddlFlowMType.DataSource = sdr;
        ddlFlowMType.DataTextField = "TYPENAME";
        ddlFlowMType.DataValueField = "FLOWTYPEID";
        ddlFlowMType.DataBind();
        sdr.Close();
 
    }
    protected void btnSubmit_Click(object sender, EventArgs e)
    {
        string FlowName = txtFlowMName.Text.ToString().Trim();
        string FlowTypeID = ddlFlowMType.SelectedValue.ToString();
        string CheckSQL = "select count(*) from LCMINFO where FLOWMNAME='" + FlowName + "' and FLOWTYPEID=" + FlowTypeID + "";
        BasicClass BC = new BasicClass();
        if (BC.CheckRecordExist(CheckSQL))
        {
            txtFlowMName.Text = "";
            Response.Write("<script language='javascript'>alert('该流程已存在，请更改流程名称!');txtFlowMName.Focus();</script>");
        }
        else
        {
            FlowModel flow = new FlowModel();
            flow.FlowName = FlowName;
            flow.FlowTypeID = Convert.ToInt32(FlowTypeID);
            flow.Brief = txtFlowMBrief.Text;
            flow.UserName = Session["userName"].ToString().Trim();
            if (flow.AddFlowModel())
            {
                string flowMID = flow.GetFlowMID(flow.FlowName.ToString());
                Response.Write("<script language='javascript'>alert('添加成功！请添加该流程审批步骤。');location.href='FlowStepSet.aspx?flowid=" + flowMID + "';</script>");
            }
        }
    }
    protected void txtReset_Click(object sender, EventArgs e)
    {
        txtFlowMName.Text = "";
        txtFlowMBrief.Text = "";
        BindToDdlFlowMType(); 
    }
}
